package leetcode.剑指offer;

import java.util.Arrays;

public class 二维数组中的查找04 {
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if (matrix == null || matrix.length == 0)
            return false;
        int n = matrix.length;
        int m = matrix[0].length;

        int i = 0, j = m - 1;
        while (i != n - 1 && j != 0) {
            int temp = matrix[i][j];
            if (temp == target)
                return true;
            else if (temp > target) {
                j -= 1;
            } else if (temp < target) {
                i += 1;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int[][] matrix = {
                {-5}
        };

        new 二维数组中的查找04().findNumberIn2DArray(matrix, -5);

    }
}
